//
//  DiaryListCell.m
//  PaiLeXiongProject
//
//  Created by 小獾科技 on 2017/8/23.
//  Copyright © 2017年 小獾科技. All rights reserved.
//

#import "DiaryListCell.h"

@interface DiaryListCell ()

@property (nonatomic, strong) UIImageView *backGroundImg;

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *aLabel;
@property (nonatomic, strong) UILabel *commendLabel;

@end
@implementation DiaryListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.userInteractionEnabled = YES;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _backGroundImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, GWIDTH, 200)];
        _backGroundImg.image = IMAGE(@"");
        _backGroundImg.userInteractionEnabled = YES;
        [self addSubview:_backGroundImg];
        
        UIImageView *iv = [[UIImageView alloc] initWithFrame:_backGroundImg.frame];
        iv.image = IMAGE(@"diary_background");
        iv.userInteractionEnabled = YES;
        [_backGroundImg addSubview:iv];
        
        
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn setTitle:@"点击查看详情" forState:0];
        [_btn setTitleColor:ColorFrom16(0xffffff) forState:0];
        _btn.titleLabel.font = PFRFONT(10);
        _btn.layer.backgroundColor = ColorClear.CGColor;
        _btn.layer.borderWidth = 0.4;
        _btn.layer.borderColor = ColorFrom16(0xffffff).CGColor;
        _btn.layer.cornerRadius = 5;
        [_backGroundImg addSubview:_btn];
        [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(self).offset(143);
//            make.right.equalTo(self).offset(-143);
            make.bottom.equalTo(self).offset(-23.4);
            make.centerX.equalTo(self.mas_centerX);
//            make.width.equalTo(@87.1);
            make.width.greaterThanOrEqualTo(@50);
            make.height.equalTo(@31.6);
        }];
        
        UIView *line = [UIView new];
        line.alpha = 0.5;
        line.backgroundColor = ColorFrom16(0xffffff);
        [_backGroundImg addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(32);
            make.left.equalTo(self).offset(37);
            make.right.equalTo(self).offset(-39);
            make.height.equalTo(@0.4);
        }];
        
        UIView *line1 = [UIView new];
        line1.alpha = 0.5;
        line1.backgroundColor = ColorFrom16(0xffffff);
        [_backGroundImg addSubview:line1];
        [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(32);
            make.left.equalTo(self).offset(37);
            make.bottom.equalTo(self).offset(-39);
            make.width.equalTo(@0.4);
        }];
        
        UIView *line2 = [UIView new];
        line2.alpha = 0.5;
        line2.backgroundColor = ColorFrom16(0xffffff);
        [_backGroundImg addSubview:line2];
        [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(32);
            make.right.equalTo(self).offset(-39);
            make.bottom.equalTo(self).offset(-39);
            make.width.equalTo(@0.4);
        }];
        
        UIView *line3 = [UIView new];
        line3.alpha = 0.5;
        line3.backgroundColor = ColorFrom16(0xffffff);
        [_backGroundImg addSubview:line3];
        [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-39);
            make.left.equalTo(self).offset(37);
            make.right.equalTo(_btn.mas_left);
            make.height.equalTo(@0.4);
        }];
        
        UIView *line4 = [UIView new];
        line4.backgroundColor = ColorFrom16(0xffffff);
        line4.alpha = 0.5;
        [_backGroundImg addSubview:line4];
        [line4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-39);
            make.right.equalTo(self).offset(-39);
            make.left.equalTo(_btn.mas_right);
            make.height.equalTo(@0.4);
        }];
        
        _titleLabel = [UILabel new];
        _titleLabel.text = @"妈咪:2-6个月的婴儿游泳备记";
        _titleLabel.textColor = ColorFrom16(0xffffff);
        _titleLabel.textAlignment = 1;
        _titleLabel.font = PFMFONT(18);
        [_backGroundImg addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(70);
            make.left.equalTo(self).offset(64);
            make.right.equalTo(self).offset(-64);
            make.height.equalTo(@25);
        }];
        
        _aLabel = [UILabel new];
        _aLabel.text = @"精选";
        _aLabel.textColor = ColorFrom16(0xffffff);
        _aLabel.font = PFRFONT(14);
        [_backGroundImg addSubview:_aLabel];
        [_aLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleLabel.mas_bottom).offset(8);
            make.left.equalTo(self).offset(128);
            make.width.equalTo(@40);
            make.height.equalTo(@20);
        }];
        
        UIView *view = [UIView new];
        view.backgroundColor = ColorFrom16(0xffffff);
        view.userInteractionEnabled = YES;
        [_backGroundImg addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_aLabel.mas_right).offset(0);
            make.top.equalTo(_titleLabel.mas_bottom).offset(8);
            make.width.equalTo(@1);
            make.height.equalTo(@18);
        }];
        
        _commendLabel = [UILabel new];
        _commendLabel.text = @"853条点评";
        _commendLabel.textColor = ColorFrom16(0xfede6d);
        _commendLabel.font = PFRFONT(14);
        [_backGroundImg addSubview:_commendLabel];
        [_commendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleLabel.mas_bottom).offset(8);
            make.left.equalTo(view.mas_right).offset(6);
            make.width.greaterThanOrEqualTo(@70);
            make.height.equalTo(@20);
        }];
    }
    return self;
}


- (void)configWithModel:(DiaryOldTimeModel *)model
{
    self.titleLabel.text = model.topic_title;
    self.commendLabel.text = [NSString stringWithFormat:@"%@条点评", model.topic_sum_comment];
    [self.backGroundImg sd_setImageWithURL:[NSURL URLWithString:STRING(model.topic_logo)] placeholderImage:nil];
    self.backGroundImg.userInteractionEnabled = YES;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
